package com.leetcode.LC_MED;

import java.util.Arrays;

public class LC300 {
    public int lengthOfLIS(int[] nums) {//出错
        int[] dp = new int[nums.length];
        dp[0] = 1;
        int max = dp[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[i - 1]) {//等于前一个数不变
                dp[i] = dp[i - 1];
            } else if (nums[i] > nums[i - 1]) {//大于前一个数
                if (nums[i] < max) {
                    dp[i] = Math.max(dp[i - 1], 2);
                    if (dp[i] == 2) {
                        max = Math.min(max, nums[i]);
                    }
                } else {
                    dp[i] = dp[i - 1] + 1;
                    max = nums[i];
                }
            } else {
                dp[i] = dp[i - 1];
            }
        }
        return dp[nums.length - 1];
    }

    public int lengthOfLIS2(int[] nums) {//出错
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);
        dp[0] = 1;
        int maxSize = 1;
        for (int i = 1; i < nums.length; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
                }
            }
            maxSize = Math.max(maxSize, dp[i]);
        }
        return maxSize;
    }

    public static void main(String[] args) {
        System.out.println(new LC300().lengthOfLIS(new int[]{4, 10, 4, 3, 8, 9}));
    }
}
